const HtmlWebpackPlugin = require("html-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const CleanWebpackPlugin = require('clean-webpack-plugin');
const webpack = require('webpack');

const isProd = process.env.NODE_ENV === "production"

module.exports = {
    entry: {
        'app.bundle': './src/app.js',
        // 'contact': './src/contact.js'
    },
    output: {
        path: __dirname + '/dist',
        filename: '[name].[hash].js' 
    },
    devtool: 'source-map',
    devServer: {
        port: 9000,
        open: false,    //自动打开浏览器
        // proxy: {    
        //     "/": {  //代理,当请求/api/users时，就会代理请求 http://localhost:80/api/users
        //       target: "http://localhost:80"
        //     }
        //   },
          hot: true
      },
    plugins: [
        new HtmlWebpackPlugin({
            title: '文档的标题',
            template: './src/index.html', 
            filename: 'index.html',
            minify: {   //压缩html文件
                collapseWhitespace: true
            },
            hash: true,
            chunks: ['app.bundle']
        }),
        new HtmlWebpackPlugin({
            title: 'custom template',
            filename: 'contact.html',
            template: './src/contact.html', 
            minify: {   //压缩html文件
                collapseWhitespace: true
            },
            hash: true,
            // chunks: ['contact']
        }),
        new ExtractTextPlugin({
            filename: "styles.css",
            disable: true
        }),
        new CleanWebpackPlugin(['dist']),
        new webpack.NamedModulesPlugin(),
        new webpack.HotModuleReplacementPlugin()
    ],
    module: {
        rules: [
          {
            test: /\.less$/,
            use: ExtractTextPlugin.extract({
                fallback: "style-loader",
                use: ["css-loader?sourceMap", "less-loader?sourceMap"]
              })
          }
        ]
      }
}